import {dropDownButton} from './dropdownbutton'
import {casePrefix} from '../../funcs/index'
import { setPanReciprocal} from './recentreciprocal'

const workKeys = ['leakcheck', 'belate', 'overjob', 'dayoff', 'salary']

/**
 * 更新case按钮列表
 */
 export function caseButtons(ctx, $datas){
  const buttonList = ctx.getElementsById('case-buttons');
  const buttons = []
  const workButtons = []
  Object.entries(casePrefix).forEach(([index, item])=>{  // const [caseKey, title] = item
    $datas.forEach(caseItem=>{
      const {caseKey, title, count} = caseItem
      if (item[0] === caseKey) {
        if (!workKeys.includes(caseKey)){
          workButtons.push({ title: `${title}(${count})`, attr: {type: (index+'')} })
        } else {
          buttons.push({ title: `${title}(${count})`, attr: {type: (index+'')} })
        }
        // buttons.push({ title: `${title}: ${count}`, attr: {type: (index+'')} })
      }
    })
  })

  // 生成下拉菜单
  const dropButton = dropDownButton({buttons: workButtons, id: 'drop-button-work', title: '日常'})
  buttons.unshift(dropButton)
  
  buttonList.update({data: buttons}, function(){
    setPanReciprocal(ctx)
  })
}